package com.chainyoung.trademarket.mvp.presenter;

import com.chainyoung.common.base.CommonSubscriber;
import com.chainyoung.common.bean.UserInfo;
import com.chainyoung.common.di.scope.ActivityScope;
import com.chainyoung.common.exception.ApiException;
import com.chainyoung.common.mvp.BasePresenter;
import com.chainyoung.common.utils.RxUtils;
import com.chainyoung.trademarket.mvp.contract.LoginContract;

import java.util.TreeMap;

import javax.inject.Inject;

import static com.chainyoung.common.constant.LibConstant.IS_CUSTOME_SIZE;
import static com.chainyoung.common.constant.LibConstant.NO_RESULT_ERRORCODE;

@ActivityScope
public class LoginPresenter extends BasePresenter<LoginContract.Model, LoginContract.View> {

    @Inject
    public LoginPresenter(LoginContract.Model model, LoginContract.View rootView) {
        super(model, rootView);
    }


    public void getLogin(TreeMap<String, Object> map) {

        addSubscribe(mModel.getLogin(map)
                 .compose(RxUtils.<UserInfo>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<UserInfo>(mView,true,IS_CUSTOME_SIZE) {

                    @Override
                    public void onNext(UserInfo userInfo) {
                        mView.onLoginSuccess(userInfo);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                }));
    }


}
